package threading;

import java.sql.Time;

/**
 * @author krystal
 * @date 2022/11/23 8:32
 */
public class Demo6 {
    public static final long COUNT=10000000000L;

    public static void main(String[] args) {
        //serial();
        concurrency();
    }

    //串行执行任务
    public static void serial(){
        //记录ms级别的时间戳
        long begin= System.currentTimeMillis();
        long a=0;
        for (long i = 0; i < COUNT; i++) {
            a++;
        }
        a=0;
        for (long i = 0; i < COUNT; i++) {
            a++;
        }
        long end=System.currentTimeMillis();
        System.out.println("执行的时间间隔:"+(end-begin)+"ms");
    }

    //并行执行任务
    public static void concurrency(){
        long begin=System.currentTimeMillis();
        Thread t1=new Thread(()->{
            long a=0;
            for (long i = 0; i < COUNT; i++) {
                a++;
            }
        });
        Thread t2=new Thread(()->{
            long a=0;
            for (long i = 0; i < COUNT; i++) {
                a++;
            }
        });
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end=System.currentTimeMillis();
        System.out.println("执行的时间间隔:"+(end-begin)+"ms");
    }
}
